<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 售后订单列表
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <div class="handle-date mr10">
                    <el-date-picker
                        v-model="value1"
                        type="datetimerange"
                        range-separator="至"
                        start-placeholder="申请开始时间"
                        end-placeholder="申请结束时间"
                    ></el-date-picker>
                </div>
                <el-input
                    v-model="query.name"
                    placeholder="会员名称/会员ID/订单编号..."
                    class="handle-input mr10"
                ></el-input>

                <el-button type="primary" icon="el-icon-search" @click="handleSearch">查询</el-button>
            </div>
            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="全部" name="first"></el-tab-pane>
                <el-tab-pane label="待审核" name="second"></el-tab-pane>
                <el-tab-pane label="退款成功" name="third"></el-tab-pane>
                <el-tab-pane label="退款失败" name="fourth"></el-tab-pane>
            </el-tabs>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="id" label="退款订单号" align="center"></el-table-column>
                <el-table-column prop="name" label="订单号"></el-table-column>
                <el-table-column prop="name" label="会员名称"></el-table-column>
                <el-table-column prop="name" label="申请时间" align="center"></el-table-column>
                <el-table-column prop="name" label="退货商品数量" align="center"></el-table-column>
                <el-table-column prop="name" label="退款金额" align="center"></el-table-column>
                <el-table-column prop="name" label="收货人姓名" align="center"></el-table-column>
                <el-table-column prop="name" label="收货人手机" align="center"></el-table-column>
                <el-table-column prop="name" label="地址" align="center"></el-table-column>
                <el-table-column prop="name" label="物流单号" align="center"></el-table-column>
                <el-table-column prop="name" label="支付方式" align="center"></el-table-column>
                <el-table-column label="状态" align="center">
                    <template slot-scope="scope">
                        <el-tag
                            :type="scope.row.state==='成功'?'success':(scope.row.state==='失败'?'danger':'info')"
                        >审核中</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="250" align="center">
                    <template slot-scope="scope">
                        <el-button
                            type="primary"
                            size="mini"
                            @click="handleEdit(scope.$index, scope.row)"
                        >通过</el-button>
                        <el-button
                            type="danger"
                            size="mini"
                            @click="handleDelete(scope.$index, scope.row)"
                        >驳回</el-button>
                        <el-button
                            type
                            size="mini"
                            @click="handleDetails(scope.$index, scope.row)"
                        >查看详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- table分页 -->
            <div class="pagination">
                <div class="btns">
                    <el-button type="primary" class="handle-del mr10" @click="delAllSelection">批量通过</el-button>
                    <el-button type="danger" class="handle-del mr10" @click="delAllSelection">批量驳回</el-button>
                </div>

                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="currentPage2"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="10"
                    layout="sizes, prev, pager, next"
                    :total="pageTotal"
                ></el-pagination>
            </div>
            <!-- 拒绝原因 -->
            <el-dialog title="驳回原因" :visible.sync="Refuse" width="25%">
                <el-form ref="form" :model="form" label-width="70px">
                    <el-form-item label="驳回原因">
                        <el-input
                            type="textarea"
                            v-model="form.desc"
                            :autosize="{ minRows: 3, maxRows: 5}"
                        ></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="Refuse = false">取 消</el-button>
                    <el-button type="primary" @click="saveEdit">确 定</el-button>
                </span>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import { fetchData } from '../../api/index';
export default {
  name: 'AfterSalesOrderList',
  data() {
    return {
      query: {
        address: '',
        name: '',
        pageIndex: 1,
        pageSize: 10
      },
      tableData: [],
      multipleSelection: [],
      delList: [],
      Refuse: false,
      pageTotal: 0,
      form: {},
      idx: -1,
      id: -1,
      activeName: 'first'
    };
  },
  created() {
    this.getData();
  },
  methods: {
    // 获取 easy-mock 的模拟数据
    getData() {
      fetchData(this.query).then(res => {
        console.log(res);
        this.tableData = res.list;
        this.pageTotal = res.pageTotal || 50;
      });
    },
    // 触发搜索按钮
    handleSearch() {
      this.$set(this.query, 'pageIndex', 1);
      this.getData();
    },

    handleClick(tab, event) {
      console.log(tab, event);
    },
    // 删除操作
    handleDelete(index, row) {
      this.Refuse = true
      // // 二次确认删除
      // this.$confirm('确定要删除吗？', '提示', {
      //   type: 'warning'
      // })
      //   .then(() => {
      //     this.$message.success('删除成功');
      //     this.tableData.splice(index, 1);
      //   })
      //   .catch(() => { });
    },
    // 多选操作
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    delAllSelection() {
      const length = this.multipleSelection.length;
      let str = '';
      this.delList = this.delList.concat(this.multipleSelection);
      for (let i = 0; i < length; i++) {
        str += this.multipleSelection[i].name + ' ';
      }
      this.$message.error(`删除了${str}`);
      this.multipleSelection = [];
    },
    // 通过操作
    handleEdit(index, row) {

    },
    // 查看详情
    handleDetails() {
      this.$router.push('AfterSalesOrderDetails')
    },
    // 保存编辑
    saveEdit() {
      this.editVisible = false;
      this.$message.success(`修改第 ${this.idx + 1} 行成功`);
      this.$set(this.tableData, this.idx, this.form);
    },
    // 分页导航
    handlePageChange(val) {
      this.$set(this.query, 'pageIndex', val);
      this.getData();
    }
  }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 200px;
    display: inline-block;
}
.handle-date {
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
.pagination {
    display: flex;
    justify-content: space-between;
}
</style>
